有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Android截击无连接错误

我在我的应用程序中对10多种不同的连接类型使用相同类型的请求,除了这一种,它们都可以工作,我不知道为什么,它们之间的唯一区别是发送的参数。如果我手动发送请求(通过在URL栏中键入数据),一切都会恢复正常,但当volley尝试连接时,它会说NoConnectionError正在发生。我用我的4G连接和WIFI连接尝试过这个,它总是返回相同的结果

更新

好的,我在发送lat/long时取出了参数,现在服务器返回一个响应。我是否发送了lat/long错误

public void updateLoc(final double latitude, final double longitude, final Context context)
{
    if (context != null)
    {
        RequestQueue queue = Volley.newRequestQueue(context);
        StringRequest stringRequest = new StringRequest(Request.Method.POST, URL_FOR_ACCOUNT,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response)
                    {
                        Log.e("Network", "Response " + response);
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                if (error instanceof TimeoutError) {
                    Log.e(TAG,"Update Location Request timed out.");
                }else if (error instanceof NoConnectionError){
                    Log.e(TAG,"Update Location no connection.");
                } else if (error instanceof AuthFailureError) {
                    Log.e(TAG,"Auth failure");
                } else if (error instanceof ServerError) {
                    Log.e(TAG,"Server Error");
                } else if (error instanceof NetworkError) {
                  Log.e(TAG,"Network Error");
                } else if (error instanceof ParseError) {
                    Log.e(TAG,"Parse Error");
                }
            }
        }) {
            //adding parameters to the request
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> params = new HashMap<>();
                params.put("command", "updateLoc");
                params.put("appVersion", version);
                params.put("安卓VersionNumber", Integer.toString(Build.VERSION.SDK_INT));
                params.put("email", userEmail);
                params.put("lat", String.valueOf(latitude));
                params.put("long", String.valueOf(longitude));
                return params;
            }
        };

共 (1) 个答案

  1. # 1 楼答案

    好的,我知道我的错误是什么了,你不能发布诸如longstringboolean之类的内容,即使它们被转换为字符串名。我改变了这一行:

     params.put("long", String.valueOf(longitude));
    

    关于这一行:

     params.put("lng", String.valueOf(longitude));
    

    一切都恢复正常了。我找不到任何说明不能将其用作字符串名称的文档